package com.web;


import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import tk.mybatis.spring.annotation.MapperScan;

import java.util.HashMap;
import java.util.Map;

/**
 * @Configuration ， @EnableAutoConfiguration 和 @ComponentScan
 */
@SpringBootApplication
@EnableAsync
@Slf4j
@EnableCaching
@ServletComponentScan(basePackages="com.web")
@MapperScan(basePackages = "com.web.dao")
public class Application extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
    /**
     * Start
     */
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
        //log.info("SpringBoot Start Success");
    }
    @Bean
    public ServletRegistrationBean indexServletRegistration() {
        ServletRegistrationBean registration = new ServletRegistrationBean(new StatViewServlet());
        registration.addUrlMappings("/druid/*");
        registration.addInitParameter("loginUsername","xukk");
        registration.addInitParameter("loginPassword","xukk5621474");
        return registration;
    }
    @Bean
    public FilterRegistrationBean indexFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
       registration.setFilter( new WebStatFilter());
        registration.addUrlPatterns("/*");
        Map<String,String> map=new HashMap();
        map.put("exclusions","*.ico,/druid/*,/static/*");
        registration.setInitParameters(map);
        return registration;
    }

}
